<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">添加日程</h4>
</div>

<div class="modal-body">

    <div class="form-horizontal row">
        <form id="form_data">
            <div id="div_error" class="col-sm-12"></div>

            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">专家姓名：</label>
                <div class="col-sm-6">
                    <input type="hidden" class="form-control  " id="expertId" name="expertId">
                    <select id="select_expertName" class="select2-ajax  form-control " name="name">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>

            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">身份证号：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="idCard" disabled>
                </div>
            </div>


            <div class="form-group col-sm-6">
                <label class="col-sm-4 control-label">开始时间：</label>
                <div class="col-sm-6">
                    <div class="input-group date form_date timeInput">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control" type="text" name="startTime"  readonly>
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-6">
                <label class="col-sm-4 control-label">结束时间：</label>
                <div class="col-sm-6">
                    <div class="input-group date form_date timeInput">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control" type="text" name="endTime" readonly>
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">原　　因：</label>
                <div class="col-sm-6">
                    <select id="reason" class="form-control " id="reason" name="reason">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>


            <div class="form-group col-sm-6">
                <div class="col-sm-6 col-sm-offset-4">
                    <button type="submit"
                            class="btn btn-default btn-success"><span
                            class="glyphicon glyphicon-ok"></span>&nbsp;确&nbsp;定&nbsp;
                    </button>
                </div>
            </div>

        </form>
    </div>


</div>

<script>
    $(function () {
        $("#select_expertName").select2({
            ajax: {
                url: "expertInfo/adminEdit/selectExpertByLikeName",
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    return {
                        q: params.term,
                        page: params.page
                    };
                },
                processResults: function (data, params) {
                    params.page = params.page || 1;
                    return {
                        results: data.items,
                        pagination: {
                            more: (params.page * 30) < data.total_count
                        }
                    };
                },
                cache: true
            },
            escapeMarkup: function (markup) {
                console.log(markup);
                return markup;
            },
            minimumInputLength: 1,
            templateResult: function (repo) {
                console.log(repo);
                if (repo.loading) return repo.text;

                if (repo.data != undefined) {
                    return repo.text + " " + repo.data;
                }

            },
            templateSelection: function (repo) {
                $("#expertId").val(repo.id);
                $("#idCard").val(repo.data);
                return repo.text;
            },
            language: "zh-CN",
            tags: true,
            width: '100%'
        });


        <%--bootstrapValidator--%>
        $("#form_data").bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                },
                startTime: {
                    validators: {
                        notEmpty: {
                            message: '不能为空！'
                        }, callback: {
                            callback: function (value, validator) {
                                var var_endTime = $("#form_data").find("input[name='endTime']").val();
                                if (value != '' && var_endTime != '') {
                                    if ((new Date(value)).getTime() > (new Date(var_endTime)).getTime()) {
                                        return {
                                            valid: false,
                                            message: '开始时间不能大于结束时间'
                                        }
                                    }
                                }
                                return true;
                            }
                        }
                    }
                },
                endTime: {
                    validators: {
                        notEmpty: {
                            message: '不能为空！'
                        },
                        callback: {
                            callback: function (value, validator) {
                                var var_startTime = $("#form_data").find("input[name='startTime']").val();
                                if (value != '' && var_startTime != '') {
                                    if ((new Date(value)).getTime() < (new Date(var_startTime)).getTime()) {
                                        return {
                                            valid: false,
                                            message: '结束时间不能小于开始时间'
                                        }
                                    }
                                }
                                return true;
                            }
                        }
                    }
                },
                reason: {
                    validators: {
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            e.preventDefault();
            $.sysPlugin.superAjax({
                data: $(e.target).serialize(),
                url: '${url}',
                operateType: '${operateType}',
                showSuccessAlert: true,
                showWarnAlert: false,
                successCall: function (data) {
                    $.sysPlugin.successCallBack(data, {
                        modal: $("#modal_ajax"),
                        table: $("#table_data")
                    });

                },
                errorCall: function (data) {
                    $.sysPlugin.errorCallBack(data, {
                        form: $("#form_data")
                    })
                }
            });

        });

        $.sysPlugin.initSelect2($("#reason"), {
            url: 'dictionary/publicOpen/lockReason'
        });

        $.sysPlugin.initDateTimeInput();
    });
</script>
